package net.zjitc.action.Utils;

import java.util.List;

/**
 * Created by Administrator on 2017/3/22.
 */
public class PageBean<E> {
    //页面传过来的
    private Integer page; //当前页
    private Integer limit; //一页中有多少条数据   10

    //应该从数据库中查出来的
    private Integer count; //总共的记录数有多少条   199
    private List<E> list; //一页中数据的记录列表


    //通过计算获得
    private Integer beginIndex; //开始索引
    private Integer endIndex;  //结束索引
    private Integer pageCount;//总页数

    public PageBean(Integer page, Integer limit, Integer count, List<E> list) {
        this.page = page;
        this.limit = limit;
        this.count = count;
        this.list = list;
        //通过各种计算？？？

        //总页数
        pageCount = count/limit;
        if ((count % limit)>0){
            pageCount++;
        }
        //计算开始与结束索引
        if (pageCount<10){
            beginIndex = 1;
            endIndex = pageCount;
        }else {
            //默认显示当前页与前面4页和后面5页
            beginIndex = page - 4;
            endIndex = page + 5;
            //如果前面没有4页，则从第一页显示
            if (beginIndex < 0){
                beginIndex = 1;
                endIndex = 10; //
            }else //如果后面没有5页，则显示最后一页的前9页与最后一页
                if (endIndex>pageCount){
                    beginIndex = pageCount-9;
                    endIndex = pageCount;
                }

        }
    }

    public PageBean() {
    }

    //

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public List<E> getList() {
        return list;
    }

    public void setList(List<E> list) {
        this.list = list;
    }

    public Integer getBeginIndex() {
        return beginIndex;
    }

    public void setBeginIndex(Integer beginIndex) {
        this.beginIndex = beginIndex;
    }

    public Integer getEndIndex() {
        return endIndex;
    }

    public void setEndIndex(Integer endIndex) {
        this.endIndex = endIndex;
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

}
